package net.hg.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hg.dto.ThirdDtDto;
import net.hg.entity.ThirdDt;
import net.hg.service.ThirdDtService;
import net.hg.utils.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "三级列表相关接口")
@RestController
@RequestMapping("/third")
public class ThirdDtController {
    /**
     * 服务对象
     */
    @Resource
    private ThirdDtService thirdDtService;


    @ApiOperation("根据ID删除三级菜单")
    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable("id") Integer id){
        int i = thirdDtService.remove(id);
        if (i > 0){
            return Result.success("删除成功");
        }
        return Result.error("服务器忙！删除失败，请稍后尝试");
    }

    @ApiOperation("修改三级菜单信息")
    @PostMapping
    public Result update(@RequestBody ThirdDtDto thirdDtDto){
        ThirdDt thirdDt = new ThirdDt();
        BeanUtils.copyProperties(thirdDtDto, thirdDt);
        int i = thirdDtService.update(thirdDt);
        if (i > 0) {
            return Result.success("修改成功");
        }
        return Result.error("修改失败，请稍后尝试");
    }

}

